import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home'

Vue.use(VueRouter)

const routes = [
  {
    path: '*',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: Home
  },
  {
    path: '/buy',
    name: 'buy',
    component: () => import('@/views/Buy')
  },
  {
    path: '/order',
    name: 'order',
    component: () => import('@/views/Order'),
    redirect: '/order/tea',
    meta: {
      isLogin: true
    },
    children: [
      {
        path: 'tea',
        name: 'tea',
        component: () => import('@/views/Order/Tea')
      },
      {
        path: 'commodity',
        name: 'commodity',
        component: () => import('@/views/Order/Commodity')
      }
    ]
  },
  {
    path: '/center',
    name: 'center',
    component: () => import('@/views/Center')
  },
  {
    path: '/center/selfInfo',
    name: 'selfInfo',
    component: () => import('@/views/Center/SelfInfo'),
    meta: {
      isLogin: true
    }
  },
  {
    path: '/center/giftcard',
    name: 'giftcard',
    component: () => import('@/views/Center/GiftCard'),
    meta: {
      isLogin: true
    }
  },
  {
    path: '/center/address',
    name: 'address',
    component: () => import('@/views/Center/Address'),
    meta: {
      isLogin: true
    }
  },
  {
    path: '/center/address/search',
    name: 'search',
    component: () => import('@/views/Center/SearchMap'),
    meta: {
      isLogin: true
    }
  },
  {
    path: '/center/address/addoreditMap/:type',
    name: 'addoreditMap',
    component: () => import('@/views/Center/AddOrEditMap'),
    meta: {
      isLogin: true
    }
  },
  {
    path: '/center/socketchat',
    name: 'socketchat',
    component: () => import('@/views/Center/SocketChat'),
    meta: {
      isLogin: true
    }
  },
  {
    path: '/details/:goodsTypeId/:goodsId',
    name: 'details',
    component: () => import('@/views/Buy/Details')
  },
  // 积分商城
  {
    path: '/integralshop',
    name: 'integralshop',
    component: () => import('@/views/IntegralShop'),
    meta: {
      isLogin: true
    }
  },
  {
    path: '/integralshop/rule',
    name: 'rule',
    component: () => import('@/views/IntegralShop/Rule'),
    meta: {
      isLogin: true
    }
  },
  {
    path: '/integralshop/integraldetailed',
    name: 'integraldetailed',
    component: () => import('@/views/IntegralShop/IntegralDetailed'),
    meta: {
      isLogin: true
    }
  },
  {
    path: '/ticketdetails/:ticketTypeId/:ticketId',
    name: 'ticketdetails',
    component: () => import('@/views/IntegralShop/TicketDetails'),
    meta: {
      isLogin: true
    }
  },
  // 礼券兑换
  {
    path: '/giftexchange',
    name: 'giftexchange',
    component: () => import('@/views/GiftExchange'),
    redirect: '/giftexchange/discount',
    children: [
      {
        path: 'discount', // 优惠券兑换
        name: 'discount',
        component: () => import('@/views/GiftExchange/Discount')
      },
      {
        path: 'departmentstores', // 优惠券兑换
        name: 'departmentstores',
        component: () => import('@/views/GiftExchange/DepartmentStores')
      }
    ],
    meta: {
      isLogin: true
    }
  },
  // 卡券列表、优惠券
  {
    path: '/voucher',
    name: 'voucher',
    component: () => import('@/views/Voucher'),
    meta: {
      isLogin: true
    }
  },
  // 订单支付页面
  {
    path: '/pay',
    name: 'pay',
    component: () => import('@/views/Pay'),
    meta: {
      isLogin: true
    }
  },
  // 支付宝支付成功页面
  {
    path: '/paysuccess',
    name: 'paysuccess',
    component: () => import('@/views/Pay/PaySuccess'),
    meta: {
      isLogin: true
    }
  },
  // 订单详情
  {
    path: '/orderdetail',
    name: 'orderdetail',
    component: () => import('@/views/Order/OrderDetail'),
    meta: {
      isLogin: true
    }
  },
]

const router = new VueRouter({
  routes,
  scrollBehavior () {
    return { x: 0, y: 0 }
  }
})

export default router
